﻿using B.S.BasicData.Api.Read.Application.Command.Menu;
using B.S.BasicData.Api.Read.Application.Command.Permission;
using B.S.BasicData.Api.Read.DTOS;
using B.S.BasicData.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.BasicData.Api.Read.Controllers
{
    /// <summary>
    /// 菜单服务
    /// </summary>
    [Route("api/[controller][action]")]
    [ApiController]
    [Authorize]
    public class MenuController : ControllerBase
    {
        IMediator _mediator;

        public MenuController(IMediator mediator)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 获取菜单列表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public Task<ApiPaging<MenuDto>> GetMenuList([FromQuery] GetMenuCommand request)
        {
            return _mediator.Send(request);
        }
        /// <summary>
        /// 获取级联菜单
        /// </summary>
        /// <param name="request">请求参数</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public Task<ApiResult<List<MenuTreeDto>>> GetMenuTree([FromQuery] GetMenuTreeCommand request)
        {
            return _mediator.Send(request);
        }
        /// <summary>
        /// 获取角色权限
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public Task<ApiResult<List<RolePermissionDto>>> GetRolePermission([FromQuery] GetRolepermissionCommand request)
        {
            return _mediator.Send(request);
        }
        /// <summary>
        /// 根据角色获取用户菜单权限树
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost("GetUserMenuTree")]
        public  Task<List<UserMenuDto>> GetUserMenuTree([FromBody]GetUserMenuTreeCommand request)
        {
            return  _mediator.Send(request);
        }
    }
}
